﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;

namespace VirtualPress.Infrastructure.Entities.Repository
{
    [Table("T_MeetingItem")]
    public class T_MeetingItem : IEntity<T_MeetingItem>
    {
        [Key]
        [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }
        public int ConferenceId { get; set; }
        /// <summary>
        /// 本期刊号
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(64)]
        public string Meetingcode { get; set; }

        public DateTime StartDate { get; set; }
        /// <summary>
        /// 截稿日期
        /// </summary>
        public DateTime ArticleEndDate { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public int Status { get; set; }

        /// <summary>
        /// 会议地点
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(256)]
        public string Address { get; set; }
        /// <summary>
        /// 联系人
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(64)]
        public string ContactMan { get; set; }
        [Column(TypeName = "varchar")]
        [StringLength(64)]
        public string Phone { get; set; }
        [Column(TypeName = "varchar")]
        [StringLength(64)]
        public string Fax { get; set; }
        [Column(TypeName = "nvarchar")]
        [StringLength(256)]
        public string ZBDW { get; set; }
        [Column(TypeName = "nvarchar")]
        [StringLength(256)]
        public string CBDW { get; set; }
        /// <summary>
        /// 会议规模
        /// </summary>
        [Column(TypeName = "nvarchar")]
        [StringLength(128)]
        public string HYGM { get; set; }
        /// <summary>
        /// 联系邮箱
        /// </summary>
        public string Email { get; set; }
        /// <summary>
        /// 摘要
        /// </summary>
        [Column(TypeName = "text")]
        public string Abstract { get; set; }

        /// <summary>
        /// 会议外链地址
        /// </summary>
        [Column(TypeName = "varchar")]
        [StringLength(256)]
        public string Link { get; set; }

        /// <summary>
        /// 会议集目录
        /// </summary>
        [Column(TypeName="text")]
        public string Catalog { get; set; }
        [Column(TypeName = "text")]
        public string CallForPaper { get; set; }
        /// <summary>
        /// 作者须知
        /// </summary>
        [Column(TypeName = "text")]
        public string Announcement { get; set; }
        /// <summary>
        /// 会后旅游
        /// </summary>
        [Column(TypeName = "text")]
        public string Travel { get; set; }
        /// <summary>
        /// 日程安排
        /// </summary>
        [Column(TypeName = "text")]
        public string Schedule { get; set; }
        public int DownloadNumber { get; set; }
        public int VisitNumber { get; set; }

        public override T_MeetingItem Find(string key)
        {
            int id = Int32.Parse(key);
            return Find(c => c.Id == id);
        }

        public override T_MeetingItem Find(System.Linq.Expressions.Expression<Func<T_MeetingItem, bool>> where)
        {
            using (Context ctx = new Context())
            {
                var model = ctx.MeetingItem.FirstOrDefault(where);
                if (model != null)
                {
                    this.Abstract = model.Abstract;
                    this.Address = model.Address;
                    this.ArticleEndDate = model.ArticleEndDate;
                    this.CBDW = model.CBDW;
                    this.ConferenceId = model.ConferenceId;
                    this.ContactMan = model.ContactMan;
                    this.DownloadNumber = model.DownloadNumber;
                    this.Email = model.Email;
                    this.Fax = model.Fax;
                    this.HYGM = model.HYGM;
                    this.Id = model.Id;
                    this.Link = model.Link;
                    this.Meetingcode = model.Meetingcode;
                    this.Phone = model.Phone;
                    this.StartDate = model.StartDate;
                    this.Status = model.Status;
                    this.VisitNumber = model.VisitNumber;
                    this.ZBDW = model.ZBDW;
                    this.Catalog = model.Catalog;
                    this.CallForPaper = model.CallForPaper;
                    this.Announcement = model.Announcement;
                    this.Travel = model.Travel;
                    this.Schedule = model.Schedule;
                    return this;
                }
                return null;
            }
        }

        public override bool Any(System.Linq.Expressions.Expression<Func<T_MeetingItem, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.MeetingItem.Any(where);
            }
        }
    }
}
